

$(function () {
    $(".batch-reset").click(function (event) {
        var self = $(this);
        var dialog = $('#batch-dialog');
        dialog.modal('show');

        var tr = self.parent().parent();
        var n_buy_now = tr.attr("data-n_buy_now");

        var nbuynowInput = $("input[name='n_buy_now']");

        var savebtn = dialog.find("#save-batch-btn");


        nbuynowInput.val(n_buy_now);

        savebtn.attr("data-type",'update');
        savebtn.attr("data-order_id",tr.attr('data-order_id'));
    })
});




$(function () {
    $('#save-batch-btn').click(function (event) {
        event.preventDefault();
        var self = $(this);
        var dialog = $('#batch-dialog');

        var n_buy_now = $("input[name='n_buy_now']").val();

        var submitType = self.attr("data-type");
        var order_id = self.attr('data-order_id');

        zlajax.post({
            'url': '/manage/update_batch/',
            'data':{
                'n_buy_now':n_buy_now,
                'order_id':order_id,
            },
            'success':function (data) {
                dialog.modal('hide');
                if(data['code']==200){
                    window.location.reload()
                }else{
                    const timer =setInterval(() => {
                              zlalert.alertError(data['message']);
                              clearInterval(timer);
                            }, 100);
                }
            },
            'fail':function () {
                zlalert.alertNetworkError();
            }
        })
    })
});